using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Q.Framework.Extension
{
    public static class UriExtension
    {
        public static string GetSubDomain(this Uri url)
        {
            if (url.HostNameType == UriHostNameType.Dns)
            {
                string host = url.Host;
                if (host.Split('.').Length > 2)
                {
                    int firstIndex = host.IndexOf(".");
                    string subdomain = host.Substring(0, firstIndex);
                    return subdomain;
                }
            }

            return null;
        }
    }
}